package com.xisoft.devise.mapper;

import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * *
 * Created with Description:
 *
 * @version 1.0 <br>
 * @packagename: com.xisoft.devise.mapper<br>
 * @author: LiBencheng <br>
 * @computer: licheng <br>
 * @date: Created on 2022/8/25 18:44 <br>
 */
@Mapper
public interface IMetadataMapper
{

    @Select ("${sqlStr}")
    int exeUpdateSql(@Param ("sqlStr") String dynamicSql);

    @MapKey ("sdt_id")
    List< Map< String,Object > > getSysTableByCode(@Param ("syscode") String syscode);

    @MapKey ("sdt_id")
    List< Map< String,Object > > getSysTable(@Param ("syscode") String syscode);

    @MapKey ("sdf_id")
    List< Map< String,Object > > getSysTableField(@Param ("table") String table);

    @Select (" SELECT  id,pcode, type,code, value, cindex FROM sys_datacode d WHERE type = 'SystemCode' Order by pcode")
    List< Map< String,Object > > getSysDataCode( );

    @Select ("${dynamicSql}")
    List< Map > getDataBySql(@Param ("dynamicSql") String dynamicSql);

    @Select (" SELECT tab.sdt_table_en_name/*表名/视图名(英文)*/,\n" +
            "               tab.sdt_table_zh_name/*表名/视图名(中文)*/,\n" +
            "               tab.sdt_table_zh_name AS value /*表名/视图名(中文)*/,\n" +
            "               tab.sdt_table_en_name AS code /*表名/视图名(英文)*/,\n" +
            "               tab.sdt_table_type/*类型*/,\n" +
            "               tab.sdt_system_name/*系统名称*/,\n" +
            "               tab.sdt_pid/*父id*/,\n" +
            "               tab.sdt_id, /*主键id不能为空*/\n" +
            "               tab.sdt_index,/* */\n" +
            "\n" +
            "               tab.search_condition,/*搜索服务过滤条件*/\n" +
            "               tab.res_code,/*资源场景编码 */\n" +
            "\n" +
            "               'true' AS isexist,\n" +
            "               ''     AS fields\n" +
            "            /*'传表的字段属性' AS fields*/\n" +
            "        FROM sys_dic_table tab\n" +
            "        WHERE (upper (tab.sdt_table_en_name) = #{table}\n" +
            "           OR lower (tab.sdt_table_en_name) = #{table})\n" +
            "        ORDER BY tab.sdt_table_en_name")
    List< Map< String,Object > > getSysTableByCode2(@Param ("table") String table);

    @Select ("\n" +
            "        SELECT tab.sdf_field_en_name/*字段名称*/,\n" +
            "               tab.sdf_field_zh_name/*字段名称*/,\n" +
            "               tab.sdf_field_type/*字段类型*/,\n" +
            "               tab.sdf_field_length/*字段长度*/,\n" +
            "               tab.sdf_primary_key/*是否主键*/,\n" +
            "               tab.sdt_table_en_name/*表名*/,\n" +
            "               tab.sdt_system_name/*系统名*/,\n" +
            "               tab.sdf_id/*主键id不能为空*/,\n" +
            "               tab.sdt_id/*主表主键*/,\n" +
            "               tab.sdf_biz_document_no,/*业务单据号（只能有一个）NO是*/\n" +
            "               tab.is_search,/*是否支持搜索服务*/\n" +
            "               'true' AS isexist\n" +
            "        FROM sys_dic_table_field tab\n" +
            "        WHERE (upper(tab.sdt_table_en_name) = #{table}\n" +
            "            OR lower(tab.sdt_table_en_name) = #{table})\n")
    List< Map< String,Object > > getSysTableField2(@Param ("table") String table);

}
